<template>
  <div class="main">
    <a-card class="user-layout-login">
      <!-- <div class="login-left">
        <div class="showtitle">
          <h1>欢迎使用</h1>
          <h3>惠山区小型零星工程管理系统</h3>
        </div>
        <div class="showimg">
          <img :src="imgleft" style="height:320px" alt="" />
        </div>
      </div> -->
      <a-form id="formLogin" ref="formLogin" :form="form" style="width:100%" @submit="handleSubmit">
        <a-row style="margin-bottom:30px">
          <a-col style="text-align:center">
            <img :src="logoimg" style="height:80px" alt="" />
          </a-col>
        </a-row>
        <a-row style="margin-bottom:30px;">
          <a-col style="text-align:center;">
            <h2 style="font-weight: bold">梁溪区社会工作部基础信息平台</h2>
          </a-col>
        </a-row>
        <a-form-item>
          <a-input class="myInput" size="large" type="text" placeholder="用户名" v-decorator="['UserName', { rules: [{ required: true, message: '请输入帐户名' }], validateTrigger: 'change' }]"> </a-input>
        </a-form-item>
        <a-form-item>
          <a-input class="myInput" size="large" type="password" autocomplete="false" placeholder="密码" v-decorator="['Password', { rules: [{ required: true, message: '请输入密码' }], validateTrigger: 'blur' }]"> </a-input>
        </a-form-item>
        <a-form-item>
          <a-checkbox :checked="checked" @change="onChange">记住密码</a-checkbox>
        </a-form-item>

        <a-form-item style="margin-bottom:0">
          <a-button size="large" shape="round" type="primary" htmlType="submit" class="login-button" :loading="state.loginBtn" :disabled="state.loginBtn">登录</a-button>
        </a-form-item>
        <a-form-item style="margin-bottom:0;text-align:center">
          <a href="https://beian.miit.gov.cn/" style="color:rgba(0, 0, 0, 0.65)"> </a>
        </a-form-item>
        <a-form-item style="margin-bottom:0;text-align:center">
          <div style="line-height:20px">
            <a target="_blank" href=" " style="display:inline-block;text-decoration:none;height:20px;line-height:20px;">
              <!-- <img :src="beian" style="float:left;" /> -->
              <p style="float:left;height:20px;line-height:20px;margin: 0px 0px 0px 5px; color:rgba(0, 0, 0, 0.65);"></p>
            </a>
          </div>
        </a-form-item>
        <!-- <div class="user-login-other">
            <a class="register" :loading="login_form.loading">忘记密码</a>
          </div> -->
      </a-form>
    </a-card>
  </div>
</template>

<script>
import TwoStepCaptcha from '@/components/tools/TwoStepCaptcha'
import { mapActions } from 'vuex'
import { timeFix } from '@/utils/util'
import { getSmsCaptcha, get2step, login } from '@/api/login'
const testData = {
  User: {
    id: 1,
    UserName: 'admin',
    Password: '21232F297A57A5A743894A0E4A801FC3',
    TrueName: 'admin',
    DepartmentID: 1,
    IsAdmin: null,
    IsDisabled: false,
    IsDel: null,
    Remark: 'admin',
    AddTime: null,
    AddUserID: null,
    ModTime: '2015-06-25T00:29:52.373',
    ModUserID: 1,
    WS_Username: 'jd130001',
    WS_Password: '066167',
    Phone: null
  },
  RoleID: 1,
  Token: 'M6X6w1xfDF8NjM3Mjk5MzYzODg1NjM2Nzcz'
}
export default {
  components: {
    TwoStepCaptcha
  },
  data () {
    return {
      beian: require('@/assets/beian.png'),
      imgleft: require('@/assets/loginLeftPhoto.png'),
      logoimg: require('@/assets/logo-global.png'),
      customActiveKey: 'tab1',
      loginBtn: false,
      loginType: 0,
      form: this.$form.createForm(this),
      login_form: {
        loading: false
      },
      checked: true,
      state: {
        time: 60,
        loginBtn: false,
        loginType: 0,
        smsSendBtn: false
      },
      testData,
      focusItem: -1
    }
  },
  created () { },
  mounted () {

  },
  methods: {
    ...mapActions(['Login', 'Logout']),
    onChange (e) {
      this.checked = e.target.checked
    },
    handleSubmit (e) {
      e.preventDefault()
      const {
        form: { validateFields },
        state,
        customActiveKey,
        Login
      } = this

      state.loginBtn = true

      const validateFieldsKey = customActiveKey === 'tab1' ? ['UserName', 'Password'] : ['mobile', 'captcha']

      validateFields(validateFieldsKey, { force: true }, (err, values) => {
        if (!err) {
          const loginParams = { ...values }
          delete loginParams.UserName
          loginParams.UserName = values.UserName
          loginParams.Password = values.Password
          console.log(this.testData)
          login(loginParams)
            .then(res => {
              if (res) {
                Login(res.data)
                this.loginSuccess(res)
              }
            })
            .catch(err => this.requestFailed(err))
            .finally(() => {
              state.loginBtn = false
            })
        } else {
          setTimeout(() => {
            state.loginBtn = false
          }, 600)
        }
      })
    },
    loginSuccess () {
      this.$router.push({ path: '/' })
      // 延迟 1 秒显示欢迎信息
      setTimeout(() => {
        this.$notification.success({
          message: '欢迎',
          description: `${timeFix()}，欢迎回来`
        })
      }, 1000)
      this.isLoginError = false
    },
    requestFailed (err) {
      this.isLoginError = true
      this.$notification['error']({
        message: '错误',
        // description: ((err.response || {}).data || {}).message || '请求出现错误，请稍后再试',
        description: err.message,
        duration: 4
      })
    }
  }
}
</script>

<style lang="less" scoped>
.ant-card {
  // background: #ffffff;
}
.ant-card-bordered {
  border: none;
}
.user-layout-login {
  // box-shadow: 0px 0px 2px 1px #e8e8e8;
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  // right: calc(50vw - 500px);
  // margin: 0 auto;
  // top: calc(50vh - 350px);
  width: 400px;
  // border-radius: 10px;
  /deep/.ant-card-body {
    //background: linear-gradient(360deg, rgba(7, 7, 238, 0), #dddddd);
    background-color: rgba(255, 255, 255, 0.7);
    border-radius: 5px;
    padding: 24px;
  }
  /deep/.ant-input {
    text-align: center;
    &::placeholder {
      color: #646464;
      text-align: center;
    }
  }
  /deep/.has-error .ant-form-explain,
  .has-error .ant-form-split {
    text-align: center;
  }
  .myInput.ant-input {
    background-color: transparent;
    color: @primary-color;
    outline: none;
    border: none;
    border-bottom-left-radius: 0;
    border-bottom-right-radius: 0;
    border-bottom: 1px solid;
    box-shadow: none;
    padding-right: 0;
  }
  .box {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    transition: all 1s;
    backface-visibility: hidden;
    color: #d3d7f7;
    padding: 90px 40px 40px;
    box-shadow: -15px 15px 15px rgba(0, 0, 0, 0.4);
    transform: rotateY(180deg);

    &:before {
      content: '';
      position: absolute;
      top: 0;
      left: 0;
      width: 100%;
      height: 100%;
      background: linear-gradient(230deg, rgba(53, 57, 74, 0), #000);
      // opacity: .8;
      z-index: -1;
    }
  }
  .login-left {
    position: absolute;
    overflow: hidden;
    width: 60%;
    height: 100%;
    bottom: 0;
    padding: 40px;
    text-align: center;
    .showimg {
      height: 75%;
    }
    .showtitle {
      height: 25%;
      text-align: left;
      font-family: SourceHanSansSC-regular;
      > h1 {
        color: #ffffff;
      }
      > h3 {
        color: #ffffff;
      }
    }
  }
  .user-layout-login-form {
    background-color: rgb(255, 255, 255, 0.2);
    float: right;
    height: calc(100% - 48px);
    width: 100%;
    border-radius: 10px;
  }
  label {
    font-size: 14px;
  }

  .getCaptcha {
    display: block;
    width: 100%;
    height: 40px;
  }

  .forge-password {
    font-size: 14px;
  }

  button.login-button {
    background-color: #2468f2;
    padding: 0 15px;
    font-size: 16px;
    // height: 40px;
    width: 100%;
  }

  .user-login-other {
    text-align: left;
    margin-top: 24px;
    line-height: 22px;

    .item-icon {
      font-size: 24px;
      color: rgba(0, 0, 0, 0.2);
      margin-left: 16px;
      vertical-align: middle;
      cursor: pointer;
      transition: color 0.3s;

      &:hover {
        color: #1890ff;
      }
    }

    .register {
      float: right;
    }
  }
}
</style>
